<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" %> <%@ include file="time.jsp" %>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>用户注册</title>
  </head>
  <body style="text-align: left">
    <script type="text/javascript">
      function check(event) {
        let flag = 0; //flag为0代表密码没有问题

        const Uname = document.getElementById("uname").value; //首先通过文本框的id获取它的值然后进行判断
        if (Uname.length < 6) {
          //如果输入信息有误，弹出提示框
          alert("用户名最短长度为6");
          flag = 1;
        }

        const Upwd = document.getElementById("upwd").value;
        const regLower = /^.*[a-z]{1,}.*$/; //包含小写字母
        const regUpper = /^.*[A-Z]{1,}.*$/; //包含大写字母
        const regSpecial = /^.*[^a-zA-Z0-9]{1,}.*$/; //包含特殊字符
        const regNum = /^.*[0-9]{1,}.*$/; //包含数字
        //如果密码纯数字、纯小写字母、纯大写字母、纯特殊字符，禁止注册
        if (
          !regLower.test(Upwd) ||
          !regUpper.test(Upwd) ||
          !regSpecial.test(Upwd) ||
          !regNum.test(Upwd)
        ) {
          alert(
            "密码必须至少有1个数字、1个大写字母、1个小写字母和其它字符共同组成!"
          );
          flag = 1;
        }
        const checkPwd = document.getElementById("ckpwd").value;
        if (checkPwd !== Upwd) {
          alert("确认密码与密码不一致");
          flag = 1;
        }
        if (flag === 1) {
          event.preventDefault();
        }
        return flag === 0;
      }
    </script>
    <form
      action="RegisterServlet"
      method="post"
      onsubmit="return check(event);"
    >
      <table align="center">
        <div style="text-align: center">
          <h2>用户注册</h2>
        </div>
        <tr>
          <td>用&nbsp;&nbsp;户&nbsp;&nbsp;名:</td>
          <%--
          <td>
            <input
              name="username"
              type="text"
              size="21"
              minlength="6"
              maxlength="9"
              placeholder="用户名长度6-9位"
            />
          </td>
          --%>
          <td>
            <input
              id="uname"
              name="username"
              type="text"
              size="21"
              maxlength="9"
              placeholder="用户名长度6-9位"
            />
          </td>
        </tr>
        <tr>
          <td align="justify">
            密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码:
          </td>
          <td>
            <input
              id="upwd"
              name="password"
              type="password"
              size="21"
              minlength="7"
              maxlength="11"
              placeholder="密码长度7-11位"
            />
          </td>
        </tr>
        <tr>
          <td align="justify">确认密码:</td>
          <td>
            <input
              id="ckpwd"
              name="ckpassword"
              type="password"
              size="21"
              minlength="7"
              maxlength="11"
              placeholder="密码长度7-11位"
            />
          </td>
        </tr>
        <tr>
          <td align="justify">E&nbsp;&nbsp;-&nbsp;&nbsp;mail:</td>
          <td><input name="email" type="text" size="21" maxlength="21" /></td>
        </tr>
        <tr>
          <td align="justify">
            单&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;位：
          </td>
          <td>
            <input
              name="unit"
              type="text"
              size="21"
              maxlength="50"
              placeholder="填写单位名称"
            />
          </td>
        </tr>
      </table>
      <table align="center" cellspacing="12">
        <tr>
          <td align="justify">
            <input type="submit" name="submit" value="注册" />
          </td>
          <td align="justify">
            <input type="reset" name="reset" value="重置" />
          </td>
        </tr>
      </table>
    </form>
    <div align="center">
      <a href="login.jsp" name="login">跳转登录</a>
    </div>
  </body>
</html>
